package com.atguigu.ssyx.product.controller;

/**
 * @author 杨林
 * @create 2023-07-20 11:40 星期四
 * description:
 */

import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.product.SkuInfo;
import com.atguigu.ssyx.product.service.SkuInfoService;
import com.atguigu.ssyx.vo.product.SkuInfoQueryVo;
import com.atguigu.ssyx.vo.product.SkuInfoVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品Sku信息前端总控制器
 */
@Api(tags = "商品Sku管理")
@RestController
@CrossOrigin  //跨域
@RequestMapping("/admin/product/skuInfo")
public class SkuInfoController {
    
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 获取Sku分页列表
     * @return
     */
    @ApiOperation(value = "获取Sku分页列表")
    @GetMapping("/{page}/{limit}")
    public Result getPageList(@PathVariable("page") Long page,
                        @PathVariable("limit") Long limit,
                        SkuInfoQueryVo skuInfoQueryVo){
        IPage<SkuInfo> pageModel = skuInfoService.getPageList(page,limit,skuInfoQueryVo);
        return Result.ok(pageModel);
    }


    /**
     * 根据id查询商品Sku信息
     * @return
     */
    @ApiOperation(value = "根据id查询商品Sku信息")
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable("id") Long id){
        SkuInfoVo skuInfoVo = skuInfoService.getSkuInfoVoById(id);
        return Result.ok(skuInfoVo);
    }

    /**
     * 新增商品Sku信息
     * @return
     */
    @ApiOperation(value = "新增商品Sku信息")
    @PostMapping("/save")
    public Result save(@RequestBody SkuInfoVo skuInfoVo){
        skuInfoService.saveSkuInfo(skuInfoVo);
        return Result.ok();
    }

    /**
     * 更新商品Sku信息
     * @return
     */
    @ApiOperation(value = "根据id更新商品Sku信息")
    @PutMapping("/update")
    public Result updateById(@RequestBody SkuInfoVo skuInfoVo){
        skuInfoService.updateSku(skuInfoVo);
        return Result.ok();
    }

    /**
     * 根据id删除商品Sku信息
     * @return
     */
    @ApiOperation(value = "根据id删除商品Sku信息")
    @DeleteMapping("/remove/{id}")
    public Result removeById(@PathVariable("id") Long id){
        skuInfoService.removeAllById(id);
        return Result.ok();
    }

    /**
     * 根据ids批量删除商品Sku信息
     * @return
     */
    @ApiOperation(value = "根据ids批量删除商品Sku信息")
    @DeleteMapping("/batchRemove")
    public Result batchRemove(@RequestBody List<Long> ids){
        skuInfoService.removeAllByIds(ids);
        return Result.ok();
    }

    /**
     * 商品上架：根据商品id修改商品发布状态
     * @return
     */
    @ApiOperation(value = "商品上架")
    @GetMapping("/publish/{id}/{status}")
    public Result publish(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        skuInfoService.publish(id,status);
        return Result.ok();
    }

    /**
     * 商品审核：根据id修改商品审核状态
     * @return
     */
    @ApiOperation(value = "商品审核")
    @GetMapping("/check/{id}/{status}")
    public Result check(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        skuInfoService.check(id,status);
        return Result.ok();
    }

    /**
     * 新人专享
     * @return
     */
    @ApiOperation(value = "新人专享")
    @GetMapping("/isNewPerson/{id}/{status}")
    public Result isNewPerson(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        skuInfoService.isNewPerson(id,status);
        return Result.ok();
    }
    
}
